/*
 * @Author: your name
 * @Date: 2021-06-04 14:57:19
 * @LastEditTime: 2022-12-20 17:11:13
 * @LastEditors: huangbc
 * @Description: In User Settings Edit
 * @FilePath: /shb-pc-fe/src/modules/task/edit/components/TaskEditForm/methods/update.js
 */
import { TaskFieldNameMappingEnum } from '@model/enum/FieldMappingEnum.ts';
import { triggerConnectorUpdate } from '@src/util/assist';
import { isArray } from '@src/util/type'

export default {
  update({ field, newValue, oldValue }) {
    
    let { fieldName, displayName, formType } = field;
    
    if(this.relationWikiSetting.includes(fieldName) && this.wikiTaskFunction) {
      this.getLabels()
    }
    
    if (this.$appConfig.debug) {
      console.info(
        `[FormBuilder] ${displayName}(${fieldName}) : ${JSON.stringify(
          newValue
        )}`
      )
    }
    
    let value = this.value;
    
    this.$set(value, fieldName, newValue);
    
    this.$emit('input', value);
    
    triggerConnectorUpdate(this, field);
    
  },
  /** 
   * @description 更新地址数据
  */
  updateAddressValue(value) {
    this.update({ field: { fieldName: TaskFieldNameMappingEnum.Address }, newValue: value });
  },
  /** 
   * @description 更新客户数据
  */
  updateCustomerValue(value) {
    this.$eventBus.$emit('agendar-task-select-customer', value[0]?.id)
    this.update({ field: { fieldName: TaskFieldNameMappingEnum.Customer }, newValue: value });
  },
  /** 
   * @description 更新联系人数据
  */
  updateLinkmanValue(value) {
    this.update({ field: { fieldName: TaskFieldNameMappingEnum.Linkman }, newValue: value });
  },
  /** 
   * @description 更新客户数据
  */
  updateProductValue(value) {
    this.update({ field: { fieldName: TaskFieldNameMappingEnum.Product }, newValue: value });
  },
  /** 
   * @description 更新通知客户短信数据
  */
  updateTickValue(value) {
    this.update({ field: { fieldName: TaskFieldNameMappingEnum.Tick }, newValue: value });
  },
  /** 
   * @description 更新质保信息
  */
  updateQualityInfoValue(value) {
    this.update({ field: { fieldName: TaskFieldNameMappingEnum.Quality }, newValue: value });
  },
  /** 
   * @description 更新故障库信息
  */
  updateFaultLibraryValue(value) {
    this.update({ field: { fieldName: 'faultLibrary' }, newValue: value });
  }
}